﻿package Views  {
	import Player.SnakeHead;
	import flash.utils.Dictionary;
	import Events.SnakeChangeEvent;
	import flash.geom.Point;
	import flash.geom.Matrix;
	import flash.display.GraphicsPathCommand;
	import flash.display.Sprite;
	import flash.display.BlendMode;
	import flash.display.MovieClip;
	
	public class SnakeDrawingCommands {
		public static const DRAW_COMMANDS:String = "drawCommands";
		public static const DRAW_COORDS:String = "drawCoordinates";
		
		public static function getCollisionSprite(snakeChangeEvent:SnakeChangeEvent):Sprite{
			var snake:SnakeHead = snakeChangeEvent.snake;
			
			// Clone orientation to get a direction to normalize
			var circlePoint:Point = snakeChangeEvent.oldPosition.clone();
						
			// Create iverse mask
			var collMask:Sprite = new Sprite();
			collMask.blendMode = BlendMode.ERASE
			collMask.graphics.beginFill(0xFFFFFF,1);
			collMask.graphics.drawCircle(circlePoint.x,circlePoint.y,snake.thickness/2);
			collMask.graphics.endFill();
			
			// Create a collision sprite
			var collSprite:Sprite = new Sprite();
			
			// Draw shape and end fill
			collSprite.graphics.lineStyle(snake.thickness,0x000000,Game.alpha,Game.pixelHinting,Game.scaleMode,Game.caps,Game.joints);
			collSprite.graphics.moveTo(circlePoint.x,circlePoint.y);
			collSprite.graphics.lineTo(snake.position.x,snake.position.y);

			// Add mask to parent
			collSprite.addChild(collMask);

			return collSprite; 
		}
	}
}
